﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;
using Besture.UI.Common;

namespace Besture.UI.Portal.UserCenter
{
    public partial class Register : System.Web.UI.Page
    {
        private UserBaseDac _dac = null;
        private UserBaseModel _model = null;
        public string sDetail = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["registerPhoneCode"] = ""; //初始化短信验证码

            var dt = QueryDac.GetTable(string.Format(@"SELECT * FROM dbo.TBPartContent WHERE PartID=140"));
            if (dt != null && dt.Rows.Count>0)
            {
               sDetail = dt.Rows[0]["Detail"].ToString();
            }
          
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LoginClick(object sender, EventArgs e)
        {  

            var baseDac = new BaseDac<UserBaseModel>();
            _dac = new UserBaseDac();
            _model = new UserBaseModel
            {
                LoginName = txtTelphone.Value == "" ? txtemail.Value : txtTelphone.Value,
                Phone = txtTelphone.Value,
                LoginPwd = StringHelper.GetMD5(registerPwdSure.Value),
                Email = txtemail.Value,
                IsDeleted = Constants.ISDELETED_NO,
                SortID = Convert.ToInt32(SortService.GetSortID("TBUserBase", false)),
                UserType = Constants.USER_TYPE_USER,
                CheckStatus = Constants.USER_CHECK_SUCCESS,
                Updated = 0,
                UpdateTime = DateTime.Now
            };
            baseDac.LoadAddBaseModel(_model);
            int flag = _dac.Register(_model);
            if (flag > 0)
            { 
                _model = new UserBaseDac().GetModel(flag);
                Session[Constants.SESSION_WEB_USER_MODEL] = _model;
                FunHelper.Alert("恭喜你注册成功", "/Default.aspx");
            }
        }
    }
}